package com.stud.common.core.domain.echarts;

import com.stud.common.enums.SeriesTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * K: 数据字典 key 的类型
 * T: 数据类型
 *
 * @author Stud
 * @date 2023-12-13 9:19
 */
@Data
@Schema(description = "echarts数据")
public class EchartsData<K, T> implements Serializable {
    @Schema(description = "类型(bar,line)")
    private SeriesTypeEnum type;

    @Schema(description = "名称或dict的key")
    private K name;

    @Schema(description = "数据")
    private List<T> data;

    private EchartsData() {

    }

    public static <K, T> EchartsData<K, T> init(SeriesTypeEnum type, K name) {
        EchartsData<K, T> echartsData = new EchartsData<>();
        echartsData.setType(type);
        echartsData.setName(name);
        echartsData.setData(new ArrayList<>());
        return echartsData;
    }

    public static <K, T> EchartsData<K, T> init(SeriesTypeEnum type, K name, List<T> data) {
        EchartsData<K, T> echartsData = new EchartsData<>();
        echartsData.setType(type);
        echartsData.setName(name);
        echartsData.setData(data);
        return echartsData;
    }

    public EchartsData<K, T> add(T t) {
        this.data.add(t);
        return this;
    }
}
